# 数列排序
n = int(input())

w = [int(i) for i in input().split()]
w1 = w[:]

chayi = -1
w_min = 0

for idx in range(n):
    new_w=[]
    for jdx in range(idx,n):
        new_w.append(w1[jdx])
    for jdx in range(idx):
        new_w.append(w1[jdx])

    w = new_w[:]
    for i in range(1,n-1):
        a,b = 0,0
        for j in range(n):
            if j<i:
                a+=w[j]
            else:
                b+=w[j]

    if chayi==-1:
        chayi = abs(a-b)
        w_min=min(a,b)
    else:
        if abs(a-b)<chayi:
            chayi = abs(a-b)
            w_min=min(a,b)

    if w_min<=0:
        break

print("{:.0f}".format(w_min))
    
